package com.senior.sendmessage.service.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.senior.sendmessage.dto.response.JokeDTO;
import com.senior.sendmessage.service.JokeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author baijiliang
 * @date 2022年09月07日 12:35
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class JokeServiceImpl implements JokeService {
    @Value("${key.jokeUrl}")
    private String jokeUrl;
    @Value("${key.jokeKey}")
    private String jokeKey;

    @Override
    public JokeDTO getJoke() {
//        Map<String, Object> key = MapUtil.newHashMap();
//        key.put("key",jokeKey);
        String result = HttpUtil.get(jokeUrl, Map.of("key", jokeKey));
        return JSONUtil.toBean(result, JokeDTO.class);
    }
}
